package com.meng.mmlive.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.meng.baselibrary.adapter.BaseRecycleViewAdapter;
import com.meng.mmlive.App;
import com.meng.mmlive.R;
import com.meng.mmlive.entity.HomeMenu;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/14.
 */

public class HomeAnchorRecyclerViewAdapter extends BaseRecycleViewAdapter<HomeMenu.DataListBean> {
    public HomeAnchorRecyclerViewAdapter(Context context) {
        super(context);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
        return new ItemHolder(getInflater().inflate(R.layout.item_home_anchor, null));
    }

    @Override
    public int getItemCount() {
        return super.getItemCount() > 3 ? 3:super.getItemCount();
    }

    @Override
    protected void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemHolder itemHolder = (ItemHolder) holder;
        itemHolder.username.setText(getItem(position).getNickName());
        String headm = getItem(position).getHeadm();
        String img = App.getStr(headm,"_100-");
        Log.d("HomeAnchorRecyclerViewA", img);
        itemHolder.userIcon.setImageURI(img);
    }

    class ItemHolder extends ItemViewHolder {
        @Bind(R.id.user_icon)
        SimpleDraweeView userIcon;
        @Bind(R.id.username)
        TextView username;
        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            int width = (App.instance.screenW- dp2px(24))/3;
            itemView.setLayoutParams(new ViewGroup.LayoutParams(width, -2));
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width- dp2px(30),width- dp2px(30));
            userIcon.setLayoutParams(layoutParams);
        }
    }
    public static int dp2px(float paramFloat)
    {
        return (int)(0.5F + paramFloat * App.instance.getResources().getDisplayMetrics().density);
    }
}
